package com.vancouver.knows.business.tracker;

import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.Constants;
import com.vancouver.knows.business.bean.UserPostDetailInfo;
import com.vancouver.knows.business.bean.UserPostInfo;

/**
 * Created by Chris Li on 2016-07-15.
 */
public class FetchUserPostDetailTracker extends ABInvokeTracker {

    public FetchUserPostDetailTracker(BusinessModule module, IResultReceiver resultReceiver) {
        super(module, resultReceiver);
    }

    @Override
    public String TAG() {
        return FetchUserPostDetailTracker.class.getSimpleName();
    }

    @Override
    public void handleResult(OperateResult result) {
        UserPostDetailInfo userPostDetailInfo = (UserPostDetailInfo) result.getResultData();
        if (userPostDetailInfo != null) {
            module.getCacheManager().getUserPostDetailInfoCache().put(userPostDetailInfo.getPostDetails().getId(), userPostDetailInfo);

            UserPostInfo userPostInfo = module.getCacheManager().getUserPostsInfoCache().getItemInfoById(userPostDetailInfo.getPostDetails().getId());
            if (userPostInfo != null) {
                if (userPostInfo.getCommentCount() != userPostDetailInfo.getPostDetails().getCommentCount()) {
                    userPostInfo.setCommentCount(userPostDetailInfo.getPostDetails().getCommentCount());
                    imContext.handleMobEmptyMessage(Constants.BUSINESS_STATUS_USERPOST_COMMENT_COUNT_CHANGE);
                }
            }
        }
    }
}
